﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.IO;

namespace NuaTarDoneng.Tail
{
    /// <summary>
    /// service 的摘要说明
    /// </summary>
    public class service : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            string result = "";
            string action=context.Request.QueryString["action"];
            string key = context.Request.QueryString["key"];
            string info = context.Request["info"];
            string pubkey = File.ReadAllText(context.Server.MapPath("/Tail/pubkey.txt"));
            string did = SecurityMan.Decodes(pubkey, key);
            string uid = tailSql.getUid(did);
            string ninfo = SecurityMan.Decodes(pubkey, info);
            if (action == "updateGPS" && null != context.Application["Status" + uid])
            {
                string dt = DateTime.Now.ToString("yyMMddHHmmss");
                string infos = "#" + dt + "," + info + "*";
                tailSql.appendLast(uid, "tline", infos);
                context.Application["Status" + uid] = info;
                result = "OK";
            }
            context.Response.Write(result);
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}